package com.liuhengjia.langchain4japply.api;

import com.liuhengjia.langchain4japply.config.assistant.Assistant;
import dev.langchain4j.data.message.SystemMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统提示词 API
 */
@RestController
@RequestMapping("/api/system-prompt")
@RequiredArgsConstructor
public class SystemPromptAPI {
    private final ChatLanguageModel chatLanguageModel;
    private final Assistant baseAssistant;

    /**
     * 低级聊天
     *
     * @param message 用户信息
     * @return 模型响应
     */
    @GetMapping("/low/chat")
    public String lowChat(@RequestParam(value = "message") String message) {
        return chatLanguageModel.chat(List.of(
                SystemMessage.from("假如你是漫威宇宙中的贾维斯，接下来请以贾维斯的语气来对话。"),
                UserMessage.from(message)
        )).aiMessage().text();
    }

    /**
     * 高级聊天
     *
     * @param message 用户信息
     * @return 模型响应
     */
    @GetMapping("/high/chat")
    public String highChat(@RequestParam(value = "message") String message) {
        return baseAssistant.systemPromptChat(message);
    }
}
